/** in order to use this demo, you'll need to set up the custom settings for CFF
 *  createa a Custom Setting callsed CloudFilesForceSettings if it is not already in
 *  your org.  add two text fields, 'username' and 'authkey', and populate them with
 *  your RackSpace cloud info (see dev guide if you need help finging your authkey)
**/
public class CloudFilesForceDemoCon {
    
    CloudFilesForceSettings__c settings = CloudFilesForceSettings__c.getInstance();
    CloudFilesForce cff = new CloudFilesForce(settings.username__c,settings.authkey__c);
    
    public string containerselected {get; set;}
    public string getselectedcontainer(){return containerselected; }
	public List<selectoption> containerslist = new List<selectoption>();

    public list<CloudFilesForce.cfObject> objects = new List<CloudFilesForce.cfObject>();
    public list<CloudFIlesForce.cfCDNContainer> cdnContainers = new list<CloudFilesForce.cfCDNContainer>();
    list<cloudfilesforce.cfContainer> containers = new list<cloudfilesforce.cfContainer>();
    
    public PageReference refreshContainers(){
        containerslist.clear();
        containerslist.add(new SelectOption('','select a container'));
		
        try{
	       	containers = cff.getContainerList();
	        
	       	for(cloudfilesforce.cfcontainer o : containers){
				containerslist.add(new selectoption(o.name,o.name + ' (' + o.count + ' objects)' ));
	        	}        	
	    }catch (exception e){
	    	ApexPages.addMessages(e);         	
	    }		
        
        try{
	    	cdnContainers = cff.getCdnContainerList();    		
    	}catch (exception e){
    		ApexPages.addMessages(e);
    	}
    	system.debug(logginglevel.debug,'cdn containers: ' + cdnContainers);
        
        return null;    	
    }
    
    public list<selectoption> getContainerList(){
        return containerslist;
    }
    
    public PageReference refreshObjects(){
        if(containerselected != null && containerselected != ''){
	        try{
	        	objects = cff.getObjectsFromContainer(getselectedcontainer());
	            system.debug(logginglevel.debug,'objects: ' + objects);        
	        }catch (exception e){
	    		ApexPages.addMessages(e);        	
	        }
        }
        return null;    	
    }
    
    public list<cloudfilesforce.cfobject> getObjects(){

        return objects;
    }
    
    public list<cloudfilesforce.cfCDNContainer> getCdnContainers(){
    	return cdnContainers;
    }
    
    public PageReference updateItems(){
    	return null;
    }
    
}